﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZG_member.Model;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
namespace ZG_member.DAL
{
   public partial  class informationShare
    {

        /// <summary>
        /// 增加一条数据
        /// </summary>
       public int Add(ZG_member.Model.informationShare model)
       {
           string str = "insert into informationShare(name,contact,createDate,appointmentDate,appointmentWays,status,memo) values(@name,@contact,@createDate,@appointmentDate,@appointmentWays,@status,@memo)";
           SqlParameter[] p = {
                              new SqlParameter("@name",SqlDbType.NVarChar,50),
                              new SqlParameter("@contact",SqlDbType.NVarChar,50),
                              new SqlParameter("@createDate",SqlDbType.DateTime,50),
                              new SqlParameter("@appointmentDate",SqlDbType.DateTime,50),
                              new SqlParameter("@appointmentWays",SqlDbType.NVarChar,50),
                              new SqlParameter("@status",SqlDbType.NVarChar,50),
                              new SqlParameter("@memo",SqlDbType.NVarChar,500),
                              };
           p[0].Value = model.name;
           p[1].Value = model.contact;
           p[2].Value = model.createDate;
           p[3].Value = model.appointmentDate;
           p[4].Value = model.appointmentWays;
           p[5].Value = model.status;
           p[6].Value = model.memo;

           object obj = DbHelperSQL.ExecuteSql(str.ToString(), p);
           if (obj == null)
           {
               return 0;
           }
           else
           {
               return Convert.ToInt32(obj);
           }

       }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// 
       public DataSet getAppointList(string strWhere)
       {
           StringBuilder sb = new StringBuilder();
           sb.Append("select id, name,contact,createDate,appointmentDate,appointmentWays,status,memo from informationShare");
           if (strWhere.Trim() != "")
           {
               sb.Append(" where "+strWhere);
           }
           return DbHelperSQL.Query(sb.ToString());
       }
       /// <summary>
       /// 得到一个对象实体
       /// </summary>
       //public ZG_member.Model.informationShare getModel(int id)
       //{
       //    string str = "select top1,id, name,contact,createDate,appointmentDate,appointmentWays,status,memo from informationShare where id=@id";

       //} 

       /// <summary>
       /// 更新一条数据
       /// </summary>
       /// 
       public int Update(int id, ZG_member.Model.informationShare model)
       {
           StringBuilder sb = new StringBuilder();
           sb.Append("update informationShare set name=@name,contact=@contact,createDate=@createDate,appointmentDate=@appointmentDate,appointmentWays=@appointmentWays,status=@status,memo=@memo");
           sb.Append(" where id=@id");
           SqlParameter[] p = {
                              new SqlParameter("@name",SqlDbType.NVarChar,50),
                              new SqlParameter("@contact",SqlDbType.NVarChar,50),
                              new SqlParameter("@createDate",SqlDbType.DateTime,50),
                              new SqlParameter("@appointmentDate",SqlDbType.DateTime,50),
                              new SqlParameter("@appointmentWays",SqlDbType.NVarChar,50),
                              new SqlParameter("@status",SqlDbType.NVarChar,50),
                              new SqlParameter("@memo",SqlDbType.NVarChar,500),
                              new SqlParameter("@id",SqlDbType.Int,10)
                              };
           p[0].Value = model.name;
           p[1].Value = model.contact;
           p[2].Value = model.createDate;
           p[3].Value = model.appointmentDate;
           p[4].Value = model.appointmentWays;
           p[5].Value = model.status;
           p[6].Value = model.memo;
           p[7].Value = id;
           object obj = DbHelperSQL.ExecuteSql(sb.ToString(), p);
           if (obj == null)
           {
               return 0;
           }
           else
           {
               return Convert.ToInt32(obj);
           }
       }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// 
       public int del(int id)
       {
           string str = "delete from informationShare where id=@id";
           SqlParameter[] p = { 
                              new SqlParameter("@id",SqlDbType.Int,10)
                              };
           p[0].Value = id;
           return DbHelperSQL.ExecuteSql(str,p);
       }
    }
}
